package org.gitos.cloud;

import org.gitos.cloud.cmd.interceptor.AuthInterceptor;
import org.gitos.cloud.domain.device.Router;
import org.gitos.cloud.domain.redis.DeviceRedisTemplate;
import org.gitos.cloud.util.RedisHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

/**
 * Created by shizhengchu on 16/3/1.
 */
@SpringBootApplication
@ImportResource("classpath:xml/dubbox.xml")
@EnableRedisHttpSession
public class Application implements CommandLineRunner {

	@Autowired
	private AuthInterceptor authInterceptor;
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	@Value("${session.expireTime}")
	private int expireTime;

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	public void run(String... args) throws Exception {
		RedisHelper.setStringRedisTemplate(stringRedisTemplate);
		RedisHelper.setExpireTime(expireTime);
	}

	@Bean
	public DeviceRedisTemplate deviceRedisTemplate(JedisConnectionFactory fc) {
		return new DeviceRedisTemplate(fc);
	}

	@Bean
	public Router router(DeviceRedisTemplate redisTemplate) {
		Router router = new Router(redisTemplate);
		return router;
	}

}
